export const commands = [
	"undo",
	"redo",
	"bold",
	"italic",
	"underline",
	"strikeThrough",
	"superscript",
	"subscript",
	// 对光标插入位置或者所选内容进行文字对齐
	"justifyCenter",
	"justifyFull",
	"justifyLeft",
	"justifyRight",
	// 对所选内容去除所有格式
	"removeFormat",
	"insertHorizontalRule",
	"insertUnorderedList",
	"insertOrderedList",
	"createLink",
	"insertImage",
	"table",
];

export const commandSelect = [
	"fontName",
	"fontSize",
	"heading",
	"backColor",
	"foreColor",
	"indent",
	"lineheight",
];

export const commandMap = {
	undo: {
		name: "撤销",
		command: "undo",
	},
	redo: {
		name: "重做",
		command: "redo",
	},
	fontName: {
		name: "字体名",
		command: "fontName",
		options: [
			{ label: "微软雅黑", value: "Microsoft YaHei" },
			{ label: "新罗马", value: "Times New Roman" },
			{ label: "宋体", value: "SimSun" },
			{ label: "平方", value: "PingFang SC" },
			{ label: "华文楷体", value: "STKaiti" },
			{ label: "Arial", value: "Arial" },
			{ label: "Calibri", value: "Calibri" },
			{ label: "Comic Sans MS", value: "Comic Sans MS" },
			{ label: "Verdana", value: "Verdana" },
		],
	},
	fontSize: {
		name: "字体大小",
		command: "fontSize",
		options: [
			{ label: "特小", value: "1" },
			{ label: "小", value: "2" },
			{ label: "正常", value: "3" },
			{ label: "略大", value: "4" },
			{ label: "大", value: "5" },
			{ label: "很大", value: "6" },
			{ label: "极大", value: "7" },
		],
	},
	heading: {
		name: "标题",
		command: "heading",
		options: [
			{ label: "H1", value: "H1" },
			{ label: "H2", value: "H2" },
			{ label: "H3", value: "H3" },
			{ label: "H4", value: "H4" },
			{ label: "H5", value: "H5" },
			{ label: "H6", value: "H6" },
		],
	},
	bold: {
		name: "加粗",
		command: "bold",
	},
	italic: {
		name: "斜体",
		command: "italic",
	},
	underline: {
		name: "下划线",
		command: "underline",
	},
	strikeThrough: {
		name: "删除线",
		command: "strikeThrough",
	},
	backColor: {
		name: "背景颜色",
		command: "backColor",
		options: [
			{ label: "黑", value: "black" },
			{ label: "红", value: "red" },
			{ label: "橙", value: "orange" },
			{ label: "蓝", value: "blue" },
			{ label: "绿", value: "green" },
			{ label: "白", value: "white" },
			{ label: "灰", value: "#999" },
			{ label: "浅灰", value: "#ddd" },
		],
	},
	foreColor: {
		name: "字体颜色",
		command: "foreColor",
		options: [
			{ label: "黑", value: "black" },
			{ label: "红", value: "red" },
			{ label: "橙", value: "orange" },
			{ label: "蓝", value: "blue" },
			{ label: "绿", value: "green" },
			{ label: "白", value: "white" },
			{ label: "灰", value: "#999" },
			{ label: "浅灰", value: "#ddd" },
		],
	},
	superscript: {
		name: "上标",
		command: "superscript",
	},
	subscript: {
		name: "下标",
		command: "subscript",
	},
	justifyCenter: {
		name: "居中对齐",
		command: "justifyCenter",
	},
	justifyFull: {
		name: "两端对齐",
		command: "justifyFull",
	},
	justifyLeft: {
		name: "左对齐",
		command: "justifyLeft",
	},
	justifyRight: {
		name: "右对齐",
		command: "justifyRight",
	},
	removeFormat: {
		name: "清除样式",
		command: "removeFormat",
	},
	insertHorizontalRule: {
		name: "分割线",
		command: "insertHorizontalRule",
	},
	insertUnorderedList: {
		name: "无序列表",
		command: "insertUnorderedList",
	},
	insertOrderedList: {
		name: "有序列表",
		command: "insertOrderedList",
	},
	increaseFontSize: {
		name: "字体变大",
		command: "increaseFontSize",
	},
	decreaseFontSize: {
		name: "字体变小",
		command: "decreaseFontSize",
	},
	createLink: {
		name: "插入链接",
		command: "createLink",
	},
	insertImage: {
		name: "插入图片",
		command: "insertImage",
	},
	//
	indent: {
		name: "缩进",
		command: "indent",
		options: [
			{ label: "2", value: "2" },
			{ label: "3", value: "3" },
			{ label: "4", value: "4" },
		],
	},
	lineheight: {
		name: "行高",
		command: "lineheight",
		options: [
			{ label: "1", value: "1" },
			{ label: "2", value: "2" },
			{ label: "3", value: "3" },
			{ label: "4", value: "4" },
			{ label: "5", value: "5" },
			{ label: "6", value: "6" },
			{ label: "7", value: "7" },
		],
	},
	table: {
		name: "表格",
		command: "table",
	},
};

//默认样式
export const defaultStyle = {
	paragraph: "font-size: 20px;line-height: 2;color: black; background-color: white;",
	table: "display: table;margin: 10px 0;font-size: 20px;line-height: 2;border: 1px solid #4b4a4a;text-align: center;border-spacing: 0;border-collapse: collapse;",
	text: "font-weight:normal;font-style:normal;color: black;",
	row: "padding: 10px;",
	cell: "padding: 5px;border: 1px solid #4b4a4a;word-break: break-all;",
};
// 引用样式
export const quoteStyle = {
	paragraph_id:
		"font-size: 20px;line-height: 2;color: blue; background-color: yellow;",
	table_id: "display: table;margin: 10px 0;font-size: 20px;line-height: 2;",
	text_id: "font-weight:bold;font-style:italic;color: black;",
	row_id: "",
	cell_id: "",
};
//节点样式
export const selfStyle = {
	paragraph: "font-size: 20px;line-height: 2;color: blue; background-color: yellow;",
	table: "display: table;margin: 10px 0;font-size: 20px;line-height: 2;",
	text: "font-weight:bold;font-style:italic;color: red;",
	row: "",
	cell: "padding: 5px;border: 1px solid green;word-break: break-all;",
};

export function mergeStyle(type) {
	let quoteStyle_id = "";
	for (const key in quoteStyle) {
		if (key.startsWith(type)) {
			quoteStyle_id = quoteStyle[key];
		}
	}
	return defaultStyle[type] + quoteStyle_id + selfStyle[type];
}

export function loadImage(coms) {
	return coms.map((com) => require(`../assets/image/${com}.png`));
}

export function execEditorCommand(name, args = null) {
	// document.designMode = "on";
	document.execCommand(name, false, args);
}
